<?php
namespace PsiFramework\Applications\AlloMediaUser\Classes\Actions;

import("Applications.AlloMediaUser.Classes.Actions.AddItemAction");
import("Classes.Util.HTTP.AuthenticationManager");
import("Classes.Factory.DAOFactory");
import("Plugins.Shop.Classes.Model.Order");
import("Plugins.Shop.Classes.Model.OrderItem");
import("Plugins.Shop.Classes.Model.OrderItemLink");

use \PsiFramework\Applications\AlloMediaUser\Classes\Actions\AddItemAction;
use \PsiFramework\Applications\AlloMediaPortal\Classes\Model\InformationPart;
use \PsiFramework\Classes\Util\HTTP\AuthenticationManager;
use \PsiFramework\Classes\Util\Object\Date;
use \PsiFramework\Classes\Util\Object\ReferenceObject;
use \PsiFramework\Classes\Util\Parameters\Action\ActionParameters;
use \PsiFramework\Classes\Factory\DAOFactory;
use \PsiFramework\Plugins\Shop\Classes\Model\Order;
use \PsiFramework\Plugins\Shop\Classes\Model\OrderItem;
use \PsiFramework\Plugins\Shop\Classes\Model\OrderItemLink;

/**
 * PsiFramework
 * Php Simple Framework
 *
 * @author Rémi San
 * @version beta
 */

/**
 * Classe d'action d'ajout d'un thème au panier
 *
 * @package Actions.Pages
 */
class OrderThemeAction extends AddItemAction
{

    public function __construct(ActionParameters $actionParameters)
    {
        parent::__construct($actionParameters);
    }

    /**
     * The main function of the method which is called every time
     * an action is created by the front controller.
     *
     */
    public function execute()
    {
        parent::execute();

        $quantity = $this->_request->getParameter('quantity');
        if (isNullOrEmptyString($quantity)) {
            $quantity = 1;
        }
        
        $order = $this->_response->getAttribute('order');
        $form = $this->_response->getAttribute('form');
        $entry = $this->_response->getAttribute('entry');
        $item = $this->_response->getAttribute('item');
        
        self::addItemToOrder($order, $item, $quantity);
        
        $this->findForward('success');
    }
}
